package com.paipai.controller;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.paipai.entity.Bidding;
import com.paipai.entity.Product;
import com.paipai.entity.ProductParams;
import com.paipai.service.productService;

@RestController

public class ProductController {
	
	@Autowired
	private productService  productService;
	
	
	/**
	 * 热度商品
	 * @return
	 */
	@RequestMapping("/heatProduct")
	public List<Product>  indexProduct() {
		List<Product> list = productService.heatIndexProduct();
		//System.out.println(list);
		return list;
		
	}
	
	
	/**
	 * 最新上架
	 * @return
	 */
	@RequestMapping("/newestProduct")
	public List<Product>  newestProduct() {
		List<Product> list = productService.neweIndexProduct();
		//System.out.println(list);
		return list;
		
	}
	
	
	@ResponseBody
	@RequestMapping("/discountsProduct")
	public List<Product>  discountsProduct(Integer id) {
		List<Product>  list = productService.discountsProduct();
		//System.out.println(product);
		return list;

	}
	
	
	
	
	
	
	/**
	 * 获取商品详情
	 * 
	 * @param date
	 */
	@ResponseBody
	@RequestMapping("/particulars")
	public Product productParticulars(@RequestParam("id") Integer id) {
		Product product = productService.ProductParticulars(id);
		//System.out.println(product);
		return product;

	}
	
	
	
	/**
	 * 用户搜索商品
	 * 
	 * @param date
	 */
	//@Cacheable(cacheNames="cache2")
	@ResponseBody
	@RequestMapping("/userSearch")
	public Object userSearch(ProductParams proParams) {
		//逻辑层
		HashMap<String,Object>map= productService.userSearchEsProduct(proParams);
		//System.out.println(map);
		return map;
		
	}
	
	
	/**
	 * 将storage转移到redis
	 * @param proids
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/finProductListByIds")
	public List<Product> finProductListByIds(@RequestParam("proids") String proids){
		
		List<Product> list=productService.finProductListByIds(proids);
		
		return list;
		
	};
	
	// 远程调用查看是否有到期商品
	@ResponseBody
	@RequestMapping("/findProductEndDate")
	Product findProductEndDate(@RequestParam("id") Integer id) {
		Product product = productService.ProductParticulars(id);
		return product;

	};
	
	
	

}
